package com.enjoyor.soa.traffic.frame.properties;

import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "file.handle")
public class FileHanderProperties {

    private String suffixs;

    private String fileDir;

    private String fileAddr;

    private String resource;

    private String mappingAddr;

    public FileHanderProperties() {
    }

    public String getSuffixs() {
        return suffixs;
    }

    public void setSuffixs(String suffixs) {
        this.suffixs = suffixs;
    }

    public String getFileDir() {
        return fileDir;
    }

    public void setFileDir(String fileDir) {
        this.fileDir = fileDir;
    }

    public String getFileAddr() {
        return fileAddr;
    }

    public void setFileAddr(String fileAddr) {
        this.fileAddr = fileAddr;
    }

    public String getResource() {
        return resource;
    }

    public void setResource(String resource) {
        this.resource = resource;
    }

    public String getMappingAddr() {
        return mappingAddr;
    }

    public void setMappingAddr(String mappingAddr) {
        this.mappingAddr = mappingAddr;
    }

    public String getMappingAddress(String secondDir, String fileName) {
        return fileAddr + "/" + mappingAddr + "/" + secondDir + "/" + fileName;
    }

    public String[] getSuffixsArray() {
        if (suffixs != null && !StringUtils.isBlank(suffixs)) {
            return suffixs.split(",");
        }
        return null;
    }

    public boolean isValidFile(String fileName, String... allowTypes) {
        if (allowTypes == null)
            return true;
        if (null == fileName || "".equals(fileName))
            return false;
        for (String type : allowTypes) {
            if (fileName.indexOf(type) > -1)
                return true;
            if(type.equals("*"))
                return true;
        }
        return false;
    }

}
